package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.DictionariesItem;
import cn.wolfcode.crm.mapper.DictionariesItemMapper;
import cn.wolfcode.crm.query.DictionariesQuery;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDictionariesItemService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DictionariesItemServiceImpl implements IDictionariesItemService {
    @Autowired
    private DictionariesItemMapper dictionariesItemMapper;




    public void saveOrUpdate(DictionariesItem entity) {
        if (entity.getId() == null) {
            dictionariesItemMapper.insert(entity);
        } else {
            dictionariesItemMapper.updateByPrimaryKey(entity);
        }
    }

    public void delete(Long id) {
        dictionariesItemMapper.deleteByPrimaryKey(id);
    }

    public DictionariesItem get(Long id) {
        return dictionariesItemMapper.selectByPrimaryKey(id);
    }

    public List<DictionariesItem> listAll() {
        return dictionariesItemMapper.selectAll();
    }

    @Override
    public PageResult query(DictionariesQuery qo) {
        int count = dictionariesItemMapper.queryCount(qo);
        if (count == 0) {
            return new PageResult(0, Collections.emptyList());
        }
        List<DictionariesItem> dictionariesItems = dictionariesItemMapper.queryList(qo);
        return new PageResult(count, dictionariesItems);
    }
//

}
